Can you install tidyverse?
Can you load tidyverse?
Pacman allows you to load multiple packages at once
Pacman also allows you to unload multiple packages at once
Can you ask for help for using linear regression (Hint: The linear regression function is lm() )
What is the working directory?
How to change the working directory?
Print the number 2
Add the number 2 and the number 1 together
Subtract 2 from 6
Multiply 2 by 3
Square 2
Find the remainder of 7 after divison by 2
Square root of 4
Assignment: Derive the area for a circle if the radius is 37.5. (Hint: pi is stored in R as “pi”)
Assign the number 2 to a variable titled “two” (Hint: Use “<-” or “=” for assignment)
Use auto-printing
Use explicit printing
Generate a sequence of numbers from 1 to 10 and assign to “domain”
Add sequence of numbers to variable two and assign to variable “range”
Create a vector of numbers 3, 6, 9 and assign to variable “dots” Note: c() stands for concatenate. Vectors contain variables only of same class
Plot dots
Note: This is base R plotting which is generally less favored than ggplot2. It can be useful for quick plotting, like here.
Try to create a vector with a string at end.
What do you notice about when you add a different class to the end of the vector?
Assignment: Generate a slope-intercept function with a y-intercept (b) of 2, a slope of 4, and a domain set of numbers containing 2, 7, -1, 5, 3, 2, 11, 3. Write the function as y = mx + b by storing each number as a variable.
Assignment: Print the range assigned as “y”.
Assignment: Plot “y”
Examine the class
This is not a class but… Variables can be converted to categorical factors for data analysis. Note: If a variable is a character and is used in a statistical model, it will default to a factor.
You can explicitly coerce your objects to become other classes. For example, 1’s and 0’s can be converted to logical TRUEs and FALSEs
[1] 1 0 0 1
[1] TRUE FALSE FALSE TRUE
Numbers can be converted to characters
Matrices are vectors with another dimension, so n rows by m columns. Like vectors, they must be of one class # and will otherwise be coerced.
You can create a populated matrix of 3 rows and 3 columns.
You can bind together vectors to create a matrix. For example, using cbind() to bind columns.
For example, using rbind() to bind rows.
For special cases, you can go beyond a 2-dimensional object using arrays. See a 2x5x4 array of NAs/missing values below:
Lists are a special type of object that can contain elements of different classes. Below is a list:
Lists can also contain objects of different types and sizes. Here is a list containing a matrix, a list, and a vector.
Lists can also be named
Arithmetic Operations were covered above # +, -, /, *, ^, sqrt(), %%, etc.
But there are other operations as well.
& is AND
returns true when both conditions are true
| is OR
returns true when at-least one of the condition is true
! is negation
which can be useful for logical vectors, determining the indices of which are TRUE
Load mtcars dataset
Inspect it
Inspect the column names
Examine dimensions of the data
Examine the head (top 6 rows) and tail (bottom 6 rows) of mtcars
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
mpg cyl disp hp drat wt qsec vs am gear carb
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.7 0 1 5 2
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.9 1 1 5 2
Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.5 0 1 5 4
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.5 0 1 5 6
Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.6 0 1 5 8
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.6 1 1 4 2
What is in the bottom six and top six rows?
What kind of class is mtcars?
Examine class of dataset
You can also inspect and call variable names using “$”
[1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
[16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
[31] 15.0 21.4
[1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4
[1] 160.0 160.0 108.0 258.0 360.0 225.0 360.0 146.7 140.8 167.6 167.6 275.8
[13] 275.8 275.8 472.0 460.0 440.0 78.7 75.7 71.1 120.1 318.0 304.0 350.0
[25] 400.0 79.0 120.3 95.1 351.0 145.0 301.0 121.0
What kind of class is mpg?
Check class of mpg
Index first row
Index second row
Index 3rd through 5th rows
Index 4th column
[1] 110 110 93 110 175 105 245 62 95 123 123 180 180 180 205 215 230 66 52
[20] 65 97 150 150 245 175 66 91 113 264 175 335 109
You can index without the comma but it will be interpreted as a data.frame, in contrast to above being a vector.
hp
Mazda RX4 110
Mazda RX4 Wag 110
Datsun 710 93
Hornet 4 Drive 110
Hornet Sportabout 175
Valiant 105
Duster 360 245
Merc 240D 62
Merc 230 95
Merc 280 123
Merc 280C 123
Merc 450SE 180
Merc 450SL 180
Merc 450SLC 180
Cadillac Fleetwood 205
Lincoln Continental 215
Chrysler Imperial 230
Fiat 128 66
Honda Civic 52
Toyota Corolla 65
Toyota Corona 97
Dodge Challenger 150
AMC Javelin 150
Camaro Z28 245
Pontiac Firebird 175
Fiat X1-9 66
Porsche 914-2 91
Lotus Europa 113
Ford Pantera L 264
Ferrari Dino 175
Maserati Bora 335
Volvo 142E 109
Index 2 and 5th column
cyl drat
Mazda RX4 6 3.90
Mazda RX4 Wag 6 3.90
Datsun 710 4 3.85
Hornet 4 Drive 6 3.08
Hornet Sportabout 8 3.15
Valiant 6 2.76
Duster 360 8 3.21
Merc 240D 4 3.69
Merc 230 4 3.92
Merc 280 6 3.92
Merc 280C 6 3.92
Merc 450SE 8 3.07
Merc 450SL 8 3.07
Merc 450SLC 8 3.07
Cadillac Fleetwood 8 2.93
Lincoln Continental 8 3.00
Chrysler Imperial 8 3.23
Fiat 128 4 4.08
Honda Civic 4 4.93
Toyota Corolla 4 4.22
Toyota Corona 4 3.70
Dodge Challenger 8 2.76
AMC Javelin 8 3.15
Camaro Z28 8 3.73
Pontiac Firebird 8 3.08
Fiat X1-9 4 4.08
Porsche 914-2 4 4.43
Lotus Europa 4 3.77
Ford Pantera L 8 4.22
Ferrari Dino 6 3.62
Maserati Bora 8 3.54
Volvo 142E 4 4.11
Index column for “cyl”
Index column for “cyl” and “wt”
cyl wt
Mazda RX4 6 2.620
Mazda RX4 Wag 6 2.875
Datsun 710 4 2.320
Hornet 4 Drive 6 3.215
Hornet Sportabout 8 3.440
Valiant 6 3.460
Duster 360 8 3.570
Merc 240D 4 3.190
Merc 230 4 3.150
Merc 280 6 3.440
Merc 280C 6 3.440
Merc 450SE 8 4.070
Merc 450SL 8 3.730
Merc 450SLC 8 3.780
Cadillac Fleetwood 8 5.250
Lincoln Continental 8 5.424
Chrysler Imperial 8 5.345
Fiat 128 4 2.200
Honda Civic 4 1.615
Toyota Corolla 4 1.835
Toyota Corona 4 2.465
Dodge Challenger 8 3.520
AMC Javelin 8 3.435
Camaro Z28 8 3.840
Pontiac Firebird 8 3.845
Fiat X1-9 4 1.935
Porsche 914-2 4 2.140
Lotus Europa 4 1.513
Ford Pantera L 8 3.170
Ferrari Dino 6 2.770
Maserati Bora 8 3.570
Volvo 142E 4 2.780
Index column for “cyl” and “wt” and move “wt” before “cyl”
wt cyl
Mazda RX4 2.620 6
Mazda RX4 Wag 2.875 6
Datsun 710 2.320 4
Hornet 4 Drive 3.215 6
Hornet Sportabout 3.440 8
Valiant 3.460 6
Duster 360 3.570 8
Merc 240D 3.190 4
Merc 230 3.150 4
Merc 280 3.440 6
Merc 280C 3.440 6
Merc 450SE 4.070 8
Merc 450SL 3.730 8
Merc 450SLC 3.780 8
Cadillac Fleetwood 5.250 8
Lincoln Continental 5.424 8
Chrysler Imperial 5.345 8
Fiat 128 2.200 4
Honda Civic 1.615 4
Toyota Corolla 1.835 4
Toyota Corona 2.465 4
Dodge Challenger 3.520 8
AMC Javelin 3.435 8
Camaro Z28 3.840 8
Pontiac Firebird 3.845 8
Fiat X1-9 1.935 4
Porsche 914-2 2.140 4
Lotus Europa 1.513 4
Ford Pantera L 3.170 8
Ferrari Dino 2.770 6
Maserati Bora 3.570 8
Volvo 142E 2.780 4
Index 3rd row and 5th column
Index 2nd, 3rd, and 5th column and 3rd through 6th rows
Subset rows of wt that are less than 3
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
Subset rows where vs is 1
mpg cyl disp hp drat wt qsec vs am gear carb
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
Subset rows where carb is NOT 4
mpg cyl disp hp drat wt qsec vs am gear carb
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3
Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3
Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
While less commonly used, you can also read and write text data as tab delimited, semicolon delimited, space delimited, etc.
There are also proprietary data types for software such as SPSS (.sav), STATA (.dta), SAS (.sas7bdat)
Write csv to your working directory (comma delimited)
Can also write csv to you working directory that is semicolon delimited
Can also write tsv to your working directory
To write and import xlsx files, you will need the xlsx package
The “haven” package will allow you to read and write SPSS files such as .sav, SAS files, and STATA files
You can save you environment/workspace as well
Clear workspace
Load workspace
Base read csv
readr’s read_csv much faster
fread 2.5x faster than read_csv fread is fast and efficient but is also cool because it automatically detects the number of columns, rows, and the delimiter! So it will determine if your input is tab separated or comma separated fo example.
We can also read in that mtcars dataset again as a tsv or as a ; separated dataset
Read in the tsv file with readr
Read in the tsv file with base
Importing a sav file from SPSS
Reading in an xlsx file
What is the row number for this dataset?
What is the column number for this dataset?
What are the dimensions for this dataset? Use the function for this.
What are the variable names for the dataset?
We want to convert Farenheit to Celsius Farenheit to Celsius is (F-32)*(5/9)
What is 72F in C?
What is 50F in C?
What is 32F in C?
What is 102F in C?
What is 20F in C?
We have to re-write or copy and paste that code each time. Is there a more efficient way?
What is 72F in C?
What is 50F in C?
What is 32F in C?
What is 102F in C?
What is 20F in C?
Ultimately, you see that less code is needed here.
Exercise: Concatenating two strings with paste0 produces: paste0(‘a’,‘b’)… ‘ab’.
Write a function called ‘fence’ that takes two parameters called original and wrapper and returns a new string that has the wrapper character at the beginning and end of the original. A call to your function as fence(‘word’,‘*’) should produce ‘*word*’
Wrap “+” around “pizza”
What happens if you switch the order though?
Order of inputs matters! If you order the inputs in the order of the arguments, it will make no difference.
But if you order the inputs in a different order than the arguments in how the function is specified, you must make arguments explicit. For example…
We can also add defaults for the functions. For example, maybe if someone doesn’t specify a wrapper, we assume they just want to print the word without a wrapper.
Do you have an intuition for how we might implement that?
Ok, here’s what it would look like:
Try it out on “pizza” as the input word without a wrapper using the variant of the function with an empty default for the wrapper
You may have noticed that in the first example for converting temperatures, we used a return argument. While for this example, we did not. return is not required per se. If you did not call return, the custom function will return the last output of the function. But if you want to be explicit or call something that is not the last output, you should use return().
We want to estimate the average miles per gallon of each car
Now, we want to compute the mean miles per gallon of the car weighted by multiple different variables
Weighted by weight
Weighted by 1/4 mile time
Weighted by gross horsepower
Weighted by number of carburetors
However, doing this requires more code than is necessary.
Can you create a weighted mean custom function?
W =\frac{\sum_{i=1}^{n} w_{i} X_{i}}{\sum_{i=1}^{n} w_{i}}
Try out mpg weighted by wt, qsec, hp, carb
Can you create a formula for calculating the hypotenuse of a triangle?
\(a^2 + b^2 = h^2\)
\(\sqrt{a^2 + b^2} = h\)
Test it out!
You’ll see that h is defined within the function. Let’s try and print it outside the function.
Woah, there’s an error. Why is that?
Variables defined a function are what are called “local variables” that are only available and used in the local environment within the function but not for usage outside the function in the global environment.
Perhaps we want to implement a function which defaults to use a default input if the argument is left empty. How would we accomplish that? Let’s say for the hypotenuse function we wanted to use side a’s value if side b was not entered as an input.
These should be identical
Let’s combine it with what we’ve learned about custom functions to make it less code:
Can you loop over each row in mpg and print each row?
[1] 21
[1] 21
[1] 22.8
[1] 21.4
[1] 18.7
[1] 18.1
[1] 14.3
[1] 24.4
[1] 22.8
[1] 19.2
[1] 17.8
[1] 16.4
[1] 17.3
[1] 15.2
[1] 10.4
[1] 10.4
[1] 14.7
[1] 32.4
[1] 30.4
[1] 33.9
[1] 21.5
[1] 15.5
[1] 15.2
[1] 13.3
[1] 19.2
[1] 27.3
[1] 26
[1] 30.4
[1] 15.8
[1] 19.7
[1] 15
[1] 21.4
apply 1 over rows, 2 over columns, c(1,2) over both columns and rows
[1] 328.980 329.795 259.580 426.135 590.310 385.540 656.920 270.980 299.570
[10] 350.460 349.660 510.740 511.500 509.850 728.560 726.644 725.695 213.850
[19] 195.165 206.955 273.775 519.650 506.085 646.280 631.175 208.215 272.570
[28] 273.683 670.690 379.590 694.710 288.890
mpg cyl disp hp drat wt qsec
20.090625 6.187500 230.721875 146.687500 3.596563 3.217250 17.848750
vs am gear carb
0.437500 0.406250 3.687500 2.812500
rowMeans, colMeans, rowSums, colSums are wrappers of apply functions
[1] 29.90727 29.98136 23.59818 38.73955 53.66455 35.04909 59.72000 24.63455
[9] 27.23364 31.86000 31.78727 46.43091 46.50000 46.35000 66.23273 66.05855
[17] 65.97227 19.44091 17.74227 18.81409 24.88864 47.24091 46.00773 58.75273
[25] 57.37955 18.92864 24.77909 24.88027 60.97182 34.50818 63.15545 26.26273
mpg cyl disp hp drat wt qsec
20.090625 6.187500 230.721875 146.687500 3.596563 3.217250 17.848750
vs am gear carb
0.437500 0.406250 3.687500 2.812500
[1] 328.980 329.795 259.580 426.135 590.310 385.540 656.920 270.980 299.570
[10] 350.460 349.660 510.740 511.500 509.850 728.560 726.644 725.695 213.850
[19] 195.165 206.955 273.775 519.650 506.085 646.280 631.175 208.215 272.570
[28] 273.683 670.690 379.590 694.710 288.890
mpg cyl disp hp drat wt qsec vs
642.900 198.000 7383.100 4694.000 115.090 102.952 571.160 14.000
am gear carb
13.000 118.000 90.000
apply apply(x, MARGIN, FUN) Apply a function to the rows or columns or both Data frame or matrix vector, list, array
lapply lapply(X, FUN) Apply a function to all the elements of the input List, vector or data frame list
sapply sapply(X, FUN) Apply a function to all the elements of the input List, vector or data frame vector or matrix
Use for loops to examine the weighted mean of mpg using cyl, disp, hp, drat, wt, and qsec as weights Let’s also compare the weighted means to the overall mean
preds <- c("cyl", "disp", "hp", "drat", "wt", "qsec")
wm_output <- vector()
for (p in preds) {
wm_output[p] <- wMean(mtcars['mpg'], mtcars[p])
}
wm_output cyl disp hp drat wt qsec
18.65455 17.43239 17.97245 20.68188 18.54993 20.33536
cyl disp hp drat wt qsec
-1.4360795 -2.6582348 -2.1181708 0.5912501 -1.5406911 0.2447364
While statements will keep on going until the condition is fulfilled (i.e., TRUE). Be careful with these because if your code is ‘broken’ and the condition is unable to be made TRUE, it will run indefinitely.
Create origin dataframe
Create destination dataframe
'data.frame': 7 obs. of 2 variables:
$ surname: chr "Spielberg" "Scorsese" "Hitchcock" "Hitchcock" ...
$ title : chr "Super 8" "Taxi Driver" "Psycho" "North by Northwest" ...
'data.frame': 5 obs. of 2 variables:
$ surname : chr "Spielberg" "Scorsese" "Hitchcock" "Tarantino" ...
$ nationality: chr "US" "US" "UK" "US" ...
Merge two datasets
Can also merge by different variable names for first and second dataframe using by.x and by.y
An inner join (actually a natural join), is the most usual join of data sets that you can perform. It consists on merging two dataframes in one that contains the common elements of both, as described in the following illustration:
The outer join, also known as full outer join or full join, merges all the columns of both data sets into one for all elements.
The left join in R consist on matching all the rows in the first data frame with the corresponding values on the second. Recall that ‘Jack’ was on the first table but not on the second.
The right join in R is the opposite of the left outer join. In this case, the merge consists on joining all the rows in the second data frame with the corresponding on the first.
mpg cyl disp hp drat wt qsec vs am gear carb
15 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
16 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
24 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
7 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
17 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
31 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
14 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3
23 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
22 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
29 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
12 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
13 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3
11 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
6 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
5 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
10 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
25 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
30 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
1 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
2 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
4 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
32 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
21 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
3 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
9 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
8 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
27 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
26 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
19 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
28 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
18 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
20 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
mpg cyl disp hp drat wt qsec vs am gear carb
15 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
16 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
24 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
7 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
17 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
29 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
11 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
10 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
1 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
2 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
# A tibble: 32 × 12
cyl disp hp drat wt qsec vs am carb `3` `5` `4`
<int> <dbl> <int> <dbl> <dbl> <dbl> <int> <int> <int> <dbl> <dbl> <dbl>
1 8 472 205 2.93 5.25 18.0 0 0 4 10.4 NA NA
2 8 460 215 3 5.42 17.8 0 0 4 10.4 NA NA
3 8 350 245 3.73 3.84 15.4 0 0 4 13.3 NA NA
4 8 360 245 3.21 3.57 15.8 0 0 4 14.3 NA NA
5 8 440 230 3.23 5.34 17.4 0 0 4 14.7 NA NA
6 8 301 335 3.54 3.57 14.6 0 1 8 NA 15 NA
7 8 276. 180 3.07 3.78 18 0 0 3 15.2 NA NA
8 8 304 150 3.15 3.44 17.3 0 0 2 15.2 NA NA
9 8 318 150 2.76 3.52 16.9 0 0 2 15.5 NA NA
10 8 351 264 4.22 3.17 14.5 0 1 4 NA 15.8 NA
# … with 22 more rows
# ℹ Use `print(n = ...)` to see more rows